import HFRequest from "./index";
import { localCache } from "@/assets/utils/cache";
import { appConfig } from "../../appConfig/index";

export const hftRequest = new HFRequest(
  {
    baseURL: `http://localhost:${appConfig[import.meta.env.MODE as IEnvOType].VITE_LOCAL_PORT}`,
    interceptors: {
      requestInterceptor: (config) => {
        const token = localCache.getCache("token");
        if (token && config.headers) {
          config.headers.Authorization = `Bearer ${token}`;
        }
        return config;
      },
      requestInterceptorCatch: (err) => {
        return err;
      },
      responseInterceptor: (res) => {
        return res;
      },
      responseInterceptorCatch: (err) => {
        return err;
      }
    }
  },
  null
);
